package com.xy.biz.xd.domain.strategy.impl;

import com.xy.biz.base.client.DictClient;
import com.xy.biz.base.domain.constant.DictCodeConstant;
import com.xy.biz.base.domain.req.ListDictItemRequest;
import com.xy.biz.base.domain.resp.ListDictItemResponse;
import com.xy.biz.fd.domain.utils.DocumentPropertyUtils;
import com.xy.biz.uc.client.UserClient;
import com.xy.biz.uc.client.UserGroupClient;
import com.xy.biz.uc.domain.dto.UserDTO;
import com.xy.biz.uc.domain.dto.UserGroupDTO;
import com.xy.biz.uc.domain.req.GetUserRequest;
import com.xy.biz.uc.domain.req.ListUserGroupByIdsRequest;
import com.xy.biz.xd.domain.bo.DocumentFlowConstants;
import com.xy.biz.xd.domain.bo.DocumentReleaseBO;
import com.xy.biz.xd.domain.bo.DocumentReleaseCheckBO;
import com.xy.biz.xd.domain.converter.DocumentFlowConverter;
import com.xy.biz.xd.domain.converter.DocumentReleaseConverter;
import com.xy.biz.xd.domain.query.DocumentFlowQuery;
import com.xy.biz.xd.domain.req.GenerateDocumentRequest;
import com.xy.biz.xd.domain.req.GetDocumentFlowSimpleHandlesRequest;
import com.xy.biz.xd.domain.req.documentRelease.ListDocumentReleaseRequest;
import com.xy.biz.xd.domain.resp.GetDocumentFlowHandleResponse;
import com.xy.biz.xd.domain.resp.GetDocumentFlowResponse;
import com.xy.biz.xd.domain.strategy.ExcelModelStrategy;
import com.xy.biz.xd.manager.DocumentReleaseManager;
import com.xy.biz.xd.service.DocumentFlowHandleService;
import com.xy.biz.xd.service.DocumentFlowService;
import com.xy.biz.xd.service.DocumentReleaseService;
import com.xy.lang.util.ResultUtils;
import com.xy.tool.minio.util.LedgerTemplateUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

import static com.xy.biz.xd.domain.constant.ExcelModelConstant.RELEASE;

/**
 * @author Greekn Zhang
 * @date 2021/7/1 14:09
 * @description
 */
@Service(ExcelModelStrategy.EXCEL_MOD + RELEASE)
public class ExcelReleaseLedger implements ExcelModelStrategy {

    @Autowired
    private DocumentReleaseService documentReleaseService;
    @Autowired
    private DocumentReleaseManager documentReleaseManager;
    @Autowired
    private DocumentFlowHandleService documentFlowHandleService;
    @Autowired
    private UserClient userClient;
    @Autowired
    private UserGroupClient userGroupClient;
    @Autowired
    private DictClient dictClient;
    @Autowired
    private LedgerTemplateUtils ledgerTemplateUtils;
    private static final String LIST_TEMPLATE = "DocumentReleaseRecordTemplate.xlsx";
    private static final String ONE_TEMPLATE = "OneDocumentUseAndChangeTemplate.xlsx";

    /**
     * 根据模板类型创建表格
     */
    @Override
    public SXSSFWorkbook generate(GenerateDocumentRequest request) throws IOException {
        if (request.getFlowId() != null) {
            return generateOne(request);
        }
        //获取所有发放的流程
        //此处status和deleteFlag随便设置值，跳过MyBatis的status和deleteFlag的条件限制
        //List<DocumentReleaseBO> documentReleaseBOList = documentReleaseService.listDocumentRelease(ListDocumentReleaseRequest.builder().pageIndex(request.getPageIndex()).pageSize(request.getPageSize()).status(99).deleteFlag(false).build());
        List<DocumentReleaseBO> documentReleaseBOList = documentReleaseManager.listDocumentRelease(DocumentReleaseConverter.toQuery(request));
        Set<Long> releaseIdS = documentReleaseBOList.stream().map(DocumentReleaseBO::getDocumentReleaseId).collect(Collectors.toSet());
        //签收表
        List<DocumentReleaseCheckBO> documentReleaseCheckBOS = documentReleaseService.listDocumentReleaseCheck(releaseIdS);
        Map<Long, List<DocumentReleaseCheckBO>> map = documentReleaseCheckBOS.stream().collect(Collectors.groupingBy(DocumentReleaseCheckBO::getDocumentReleaseId));
        Map<Long, Map<Long, Long>> countReleasesCheckGroup = new HashMap<>();
        for (DocumentReleaseCheckBO documentReleaseCheckBO : documentReleaseCheckBOS) {
            Map<Long, Long> countUserCheckGroup = countReleasesCheckGroup.computeIfAbsent(documentReleaseCheckBO.getDocumentReleaseId(), (e) -> new HashMap<>());
            Long count = countUserCheckGroup.computeIfAbsent(documentReleaseCheckBO.getCheckUserGroupId(), (k) -> 0L);
            countUserCheckGroup.put(documentReleaseCheckBO.getCheckUserGroupId(), ++count);
        }
        //1、加载模板流数据
        InputStream inputStream = ledgerTemplateUtils.getUrl(LIST_TEMPLATE);
        //2.根据文件流，加载指定的工作簿
        XSSFWorkbook wb = new XSSFWorkbook(inputStream);
        SXSSFWorkbook workbook = new SXSSFWorkbook(wb);
        //3.读取工作表
        Sheet sheet = wb.getSheetAt(0);
        //4.设置表头
        Cell codeCell = sheet.getRow(0).getCell(0);
        codeCell.setCellValue(codeCell.getStringCellValue() + request.getDocumentNumber());
        Cell headerCell = sheet.getRow(1).getCell(0);
        headerCell.setCellValue(request.getDocumentHeader());
        Cell nameCell = sheet.getRow(2).getCell(0);
        nameCell.setCellValue(request.getDocumentName());
        //5.构造每行和单元格数据
        AtomicInteger datasAi = new AtomicInteger(4);
        Cell cell = null;
        CellStyle cellCenter = workbook.createCellStyle();
        CellStyle cellLeft = workbook.createCellStyle();
        cellCenter.setAlignment(HorizontalAlignment.CENTER);
        cellCenter.setVerticalAlignment(VerticalAlignment.CENTER);
        cellCenter.setBorderBottom(BorderStyle.THIN);
        cellCenter.setBorderLeft(BorderStyle.THIN);
        cellCenter.setBorderRight(BorderStyle.THIN);
        cellCenter.setBorderTop(BorderStyle.THIN);
        cellLeft.setAlignment(HorizontalAlignment.LEFT);
        cellLeft.setVerticalAlignment(VerticalAlignment.CENTER);
        cellLeft.setBorderBottom(BorderStyle.THIN);
        cellLeft.setBorderLeft(BorderStyle.THIN);
        cellLeft.setBorderRight(BorderStyle.THIN);
        cellLeft.setBorderTop(BorderStyle.THIN);
        Set<Long> userIds = documentReleaseBOList.stream().map(DocumentReleaseBO::getCreateUserId).collect(Collectors.toSet());
        //接收人Id
        userIds.addAll(documentReleaseBOList.stream().filter(d -> d.getReceiveType() == 0).map(DocumentReleaseBO::getReceiveId).collect(Collectors.toSet()));
        //接收部门Id
        Set<Long> receiveUserGroupIds = documentReleaseBOList.stream().filter(d -> d.getReceiveType() == 1).map(DocumentReleaseBO::getReceiveId).collect(Collectors.toSet());
        Map<Long, String> userDTOMap = new HashMap<>();
        Map<Long, String> userGroupDTOMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(userIds)) {
            userDTOMap = ResultUtils.get(userClient.listUserById(userIds)).stream().collect(Collectors.toMap(UserDTO::getUserId, UserDTO::getUserName));
        }
        if (!CollectionUtils.isEmpty(receiveUserGroupIds)) {
            userGroupDTOMap = ResultUtils.get(userGroupClient.listUserGroupByIds(receiveUserGroupIds)).stream().collect(Collectors.toMap(UserGroupDTO::getUserGroupId, UserGroupDTO::getUserGroupName));
        }
        Map<Long, Long> countUserByUserGroup = new HashMap<>();
        if (!CollectionUtils.isEmpty(receiveUserGroupIds)) {
            countUserByUserGroup = ResultUtils.get(userClient.listUserByUserGroup(ListUserGroupByIdsRequest.builder()
                            .groupIds(receiveUserGroupIds).build()))
                    .stream()
                    .collect(Collectors.groupingBy(e -> e.getUserGroup().getId(), Collectors.counting()));
        }
        Map<String, String> documentPropertyMap = ResultUtils.get(dictClient.listDictItem(ListDictItemRequest.builder().dictGroupCode(DictCodeConstant.DOCUMENT_CATEGORY).build())).stream().collect(Collectors.toMap(ListDictItemResponse::getDictCode, ListDictItemResponse::getDictValue));
        documentReleaseBOList.sort(Comparator.comparing(DocumentReleaseBO::getDocumentCode));
        for (int i = 0; i < documentReleaseBOList.size(); i++) {
            DocumentReleaseBO d = documentReleaseBOList.get(i);
            Row dataRow = sheet.createRow(datasAi.getAndIncrement());
            //编号
            cell = dataRow.createCell(0);
            cell.setCellValue(1 + i);
            cell.setCellStyle(cellCenter);
            //文件类型
            cell = dataRow.createCell(1);
            cell.setCellValue(documentPropertyMap.get(d.getDocumentProperty()));
            cell.setCellStyle(cellCenter);
            //文件名称
            cell = dataRow.createCell(2);
            cell.setCellValue(d.getDocumentName());
            cell.setCellStyle(cellLeft);
            //文件编号
            cell = dataRow.createCell(3);
            cell.setCellValue(d.getDocumentCode());
            cell.setCellStyle(cellCenter);
            //版本号
            cell = dataRow.createCell(4);
            cell.setCellValue(d.getDocumentVersion());
            cell.setCellStyle(cellCenter);
            //发放时间
            cell = dataRow.createCell(5);
            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            cell.setCellValue(d.getCreateTime().format(df));
            cell.setCellStyle(cellCenter);
            //发放编号/部门/人
            cell = dataRow.createCell(6);
            if (d.getReceiveType() == 0) {
                cell.setCellValue(userDTOMap.get(d.getReceiveId()));
            } else {
                cell.setCellValue(userGroupDTOMap.get(d.getReceiveId()));
            }
            cell.setCellStyle(cellCenter);
            //是否签收
            List<DocumentReleaseCheckBO> documentReleaseCheckBOS1 = map.get(d.getDocumentReleaseId());
            cell = dataRow.createCell(7);
            if (d.getReceiveType() == 0) {
                if (CollectionUtils.isEmpty(documentReleaseCheckBOS1)) {
                    cell.setCellValue("未签收");
                } else {
                    Set<Long> userId = documentReleaseCheckBOS1.stream().map(DocumentReleaseCheckBO::getCheckUserId).collect(Collectors.toSet());
                    if (userId.contains(d.getReceiveId())) {
                        cell.setCellValue("已签收");
                    } else {
                        cell.setCellValue("未签收");
                    }
                }
            } else {
                Map<Long, Long> longLongMap = countReleasesCheckGroup.get(d.getDocumentReleaseId());
                Long checkCount = CollectionUtils.isEmpty(longLongMap)
                        ? 0L : Objects.isNull(longLongMap.get(d.getReceiveId()))
                        ? 0L : longLongMap.get(d.getReceiveId());
                Long aLong = countUserByUserGroup.get(d.getReceiveId());
                Long sum = Objects.isNull(aLong) ? 0L : countUserByUserGroup.get(d.getReceiveId());
                cell.setCellValue(checkCount + "/" + sum);
            }
            cell.setCellStyle(cellCenter);
            //TODO回收日期
            cell = dataRow.createCell(8);
            if (d.getStatus() == 2) {
                cell.setCellValue(d.getUpdateTime().format(df));
            } else {
                cell.setCellValue("");
            }
            cell.setCellStyle(cellCenter);
            //备注
            cell = dataRow.createCell(9);
            cell.setCellValue("无");
            cell.setCellStyle(cellLeft);
            if (i == (documentReleaseBOList.size() - 1)) {
                int num = datasAi.getAndIncrement();
                Row row = sheet.createRow(num);
                Cell cell1 = row.createCell(0);
                cell1.setCellValue("编制人：         编制日期：         批准人：            批准日期：");
                CellRangeAddress region = new CellRangeAddress(num, num, 0, 7);
                sheet.addMergedRegion(region);
            }
        }
        return workbook;
    }

    /**
     * @author Greekn Zhang
     * @date 2021/7/12 17:27
     * @param request
     * @return org.apache.poi.xssf.streaming.SXSSFWorkbook
     * @description 单条打印
     */
    private SXSSFWorkbook generateOne(GenerateDocumentRequest request) throws IOException {
        DocumentReleaseBO response = documentReleaseService.getDocumentRelease(request.getFlowId());
        List<GetDocumentFlowHandleResponse> getDocumentFlowHandleResponses = documentFlowHandleService.listDocumentFlowNodesHandle(GetDocumentFlowSimpleHandlesRequest.builder().documentFlowId(response.getDocumentFlowId()).build());
        //1、加载模板流数据
        InputStream inputStream = ledgerTemplateUtils.getUrl(ONE_TEMPLATE);
        //FileInputStream fis = new FileInputStream(resource.getFile());
        //2.根据文件流，加载指定的工作簿
        //XSSFWorkbook wb = new XSSFWorkbook(fis);
        XSSFWorkbook wb = new XSSFWorkbook(inputStream);
        SXSSFWorkbook workbook = new SXSSFWorkbook(wb);
        //3.读取工作表
        Sheet sheet = wb.getSheetAt(0);
        //4.设置表头
        Cell codeCell = sheet.getRow(0).getCell(0);
        codeCell.setCellValue(codeCell.getStringCellValue() + request.getDocumentNumber());
        Cell headerCell = sheet.getRow(1).getCell(0);
        headerCell.setCellValue(request.getDocumentHeader());
        Cell nameCell = sheet.getRow(2).getCell(0);
        nameCell.setCellValue(request.getDocumentName());
        Cell applicationNumCell = sheet.getRow(3).getCell(3);
        applicationNumCell.setCellValue(response.getDocumentCode());
        Cell applicationTypeCell = sheet.getRow(4).getCell(1);
        applicationTypeCell.setCellValue(DocumentFlowConstants.getFlowName(response.getFlowType()));
        Cell documentNameCell = sheet.getRow(6).getCell(0);
        // TODO
        //documentNameCell.setCellValue(DocumentCodeFormatValidationUtils.getDocumentName(response.getDocumentName()));
        Cell documentCodeCell = sheet.getRow(6).getCell(2);
        documentCodeCell.setCellValue(response.getDocumentCode());
        Cell documentVersionCell = sheet.getRow(6).getCell(4);
        documentVersionCell.setCellValue(response.getDocumentVersion());
        Cell applyReasonCell = sheet.getRow(9).getCell(0);
        //获取文件评审阶段的信息
        List<GetDocumentFlowHandleResponse> apply = getDocumentFlowHandleResponses.stream().filter(d -> d.getPhase().equals(DocumentFlowConstants.PHASE_APPLY)).collect(Collectors.toList());
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        if (!CollectionUtils.isEmpty(apply)) {
            apply.sort((m1, m2) -> m2.getCreateTime().compareTo(m1.getCreateTime()));
            GetDocumentFlowHandleResponse getDocumentFlowHandleResponse = apply.get(0);
            applyReasonCell.setCellValue(applyReasonCell.getStringCellValue() + getDocumentFlowHandleResponse.getOpinion());
            //申请人部门
            Cell applyUserGroupNameCell = sheet.getRow(10).getCell(0);
            UserDTO userDTO = ResultUtils.get(userClient.getUser(GetUserRequest.builder().userId(response.getCreateUserId()).withUserGroup(true).build()));
            applyUserGroupNameCell.setCellValue(applyUserGroupNameCell.getStringCellValue() + userDTO.getUserGroup().getName());
            //申请人名称
            Cell applyCell = sheet.getRow(10).getCell(2);
            applyCell.setCellValue(applyCell.getStringCellValue() + userDTO.getUserName());
            //申请日期
            Cell applyDateCell = sheet.getRow(10).getCell(3);
            applyDateCell.setCellValue(applyDateCell.getStringCellValue() + response.getCreateTime().format(df));
        }
        //获取上传阶段的信息
        List<GetDocumentFlowHandleResponse> adminAudit = getDocumentFlowHandleResponses.stream().filter(d -> d.getPhase().equals(DocumentFlowConstants.PHASE_UPLOAD)).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(adminAudit)) {
            adminAudit.sort((m1, m2) -> m2.getCreateTime().compareTo(m1.getCreateTime()));
            //质保专员意见
            Cell qaOpinion = sheet.getRow(11).getCell(0);
            qaOpinion.setCellValue(qaOpinion.getStringCellValue() + adminAudit.get(0).getOpinion());
            Cell qaSignature = sheet.getRow(12).getCell(0);
            qaSignature.setCellValue(qaSignature.getStringCellValue() + adminAudit.get(0).getHandleUserName() + "(" + DocumentFlowConstants.getResult(adminAudit.get(0).getResult()) + ")");
            Cell qaSignatureDate = sheet.getRow(12).getCell(3);
            qaSignatureDate.setCellValue(qaSignatureDate.getStringCellValue() + adminAudit.get(0).getCreateTime().format(df));
        }
        //获取文件评审阶段的信息
        List<GetDocumentFlowHandleResponse> review = getDocumentFlowHandleResponses.stream().filter(d -> d.getPhase().equals(DocumentFlowConstants.PHASE_REVIEW)).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(review)) {
            //相关部门负责人评审意见
            review.sort((m1, m2) -> m2.getCreateTime().compareTo(m1.getCreateTime()));
            Cell managerOpinion = sheet.getRow(13).getCell(0);
            managerOpinion.setCellValue(managerOpinion.getStringCellValue() + review.get(0).getOpinion());
            Cell managerSignature = sheet.getRow(14).getCell(0);
            managerSignature.setCellValue(managerSignature.getStringCellValue() + review.get(0).getHandleUserName() + "(" + DocumentFlowConstants.getResult(review.get(0).getResult()) + ")");
            Cell managerSignatureDate = sheet.getRow(14).getCell(3);
            managerSignatureDate.setCellValue(managerSignatureDate.getStringCellValue() + review.get(0).getCreateTime().format(df));
        }
        //获取文件初步审核阶段的信息
        List<GetDocumentFlowHandleResponse> formatAudit = getDocumentFlowHandleResponses.stream().filter(d -> d.getPhase().equals(DocumentFlowConstants.PHASE_FORMAT_AUDIT)).collect(Collectors.toList());
        //质保专员/部门负责人初步审核意见
        if (!CollectionUtils.isEmpty(formatAudit)) {
            formatAudit.sort((m1, m2) -> m2.getCreateTime().compareTo(m1.getCreateTime()));
            Cell managerOpinion = sheet.getRow(15).getCell(0);
            managerOpinion.setCellValue(managerOpinion.getStringCellValue() + formatAudit.get(0).getOpinion());
            Cell managerSignature = sheet.getRow(16).getCell(0);
            managerSignature.setCellValue(managerSignature.getStringCellValue() + formatAudit.get(0).getHandleUserName() + "(" + DocumentFlowConstants.getResult(formatAudit.get(0).getResult()) + ")");
            Cell managerSignatureDate = sheet.getRow(16).getCell(3);
            managerSignatureDate.setCellValue(managerSignatureDate.getStringCellValue() + formatAudit.get(0).getCreateTime().format(df));
        }
        //获取总监文件审核/审批阶段的信息
        List<GetDocumentFlowHandleResponse> audit = getDocumentFlowHandleResponses.stream().filter(d -> d.getPhase().equals(DocumentFlowConstants.PHASE_CONTENT_AUDIT)).collect(Collectors.toList());
        //各总监审核/审批意见
        if (!CollectionUtils.isEmpty(audit)) {
            audit.sort((m1, m2) -> m2.getCreateTime().compareTo(m1.getCreateTime()));
            Cell managerOpinion = sheet.getRow(17).getCell(0);
            managerOpinion.setCellValue(managerOpinion.getStringCellValue() + audit.get(0).getOpinion());
            Cell managerSignature = sheet.getRow(18).getCell(0);
            managerSignature.setCellValue(managerSignature.getStringCellValue() + audit.get(0).getHandleUserName() + "(" + DocumentFlowConstants.getResult(audit.get(0).getResult()) + ")");
            Cell managerSignatureDate = sheet.getRow(18).getCell(3);
            managerSignatureDate.setCellValue(managerSignatureDate.getStringCellValue() + audit.get(0).getCreateTime().format(df));
        }
        //管理者代表审核/审批意见
        List<GetDocumentFlowHandleResponse> approve = getDocumentFlowHandleResponses.stream().filter(d -> d.getPhase().equals(DocumentFlowConstants.PHASE_APPROVAL)).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(approve)) {
            Integer levelNum = 0;// TODO DocumentPropertyUtils.getLevelNum(DocumentCodeFormatValidationUtils.getDocumentProperty(response.getDocumentCode()));
            approve.sort((m1, m2) -> m2.getCreateTime().compareTo(m1.getCreateTime()));
            if (levelNum == 1) {
                Cell managerOpinion = sheet.getRow(19).getCell(0);
                managerOpinion.setCellValue("总经理审核/审批意见：" + approve.get(0).getOpinion());
                Cell managerSignature = sheet.getRow(20).getCell(0);
                managerSignature.setCellValue("总经理签字：" + approve.get(0).getHandleUserName() + "(" + DocumentFlowConstants.getResult(approve.get(0).getResult()) + ")");
                Cell managerSignatureDate = sheet.getRow(20).getCell(3);
                managerSignatureDate.setCellValue(managerSignatureDate.getStringCellValue() + approve.get(0).getCreateTime().format(df));
            } else {
                Cell managerOpinion = sheet.getRow(19).getCell(0);
                managerOpinion.setCellValue(managerOpinion.getStringCellValue() + approve.get(0).getOpinion());
                Cell managerSignature = sheet.getRow(20).getCell(0);
                managerSignature.setCellValue(managerSignature.getStringCellValue() + approve.get(0).getHandleUserName() + "(" + DocumentFlowConstants.getResult(approve.get(0).getResult()) + ")");
                Cell managerSignatureDate = sheet.getRow(20).getCell(3);
                managerSignatureDate.setCellValue(managerSignatureDate.getStringCellValue() + approve.get(0).getCreateTime().format(df));
            }
        }
        return workbook;
    }
    /**
     * 根据模板类型创建表格
     *//*
    @Override
    public SXSSFWorkbook generate(GenerateDocumentRequest request) {
        Table table = new Table();
        table.setName(ExcelModelConstant.getModelName(USE_AND_CHANGE));
        List<Row> headerList = table.getHeaderList();
        Row r1 = new Row();
        //拼接页眉编号
        Cell headerCell1 = new Cell();
        headerCell1.setValue("记录编号：" + request.getDocumentNumber());
        headerCell1.setSpan(13);
        headerCell1.setHorizontalAlignment(TextAlignment.Left);
        Style headerStyle1 = new Style();
        headerStyle1.setFontSize((short) 9);
        headerCell1.setStyle(headerStyle1);
        r1.addCell(headerCell1);
        Row r2 = new Row();
        //拼接页眉
        Cell headerCell2 = new Cell();
        headerCell2.setValue(request.getDocumentHeader());
        headerCell2.setSpan(13);
        headerCell2.setHorizontalAlignment(TextAlignment.Center);
        r2.addCell(headerCell2);
        Row r3 = new Row();
        //拼接页眉编号
        Cell headerCell3 = new Cell();
        headerCell3.setValue(request.getDocumentName());
        headerCell3.setSpan(13);
        headerCell3.setHorizontalAlignment(TextAlignment.Center);
        Style headerStyle3 = new Style();
        headerStyle3.setFontSize((short) 13);
        headerStyle3.setBold(true);
        headerCell3.setStyle(headerStyle3);
        r3.addCell(headerCell3);
        headerList.add(r1);
        headerList.add(r2);
        headerList.add(r3);
        Row row = table.createRow();
        row.addCell(CellMode.genCell(CellMode.NUMBER));
        row.addCell(CellMode.genCell(CellMode.DOCUMENT_TYPE));
        row.addCell(CellMode.genCell(CellMode.DOCUMENT_NAME));
        row.addCell(CellMode.genCell(CellMode.DOCUMENT_CODE));
        row.addCell(CellMode.genCell(CellMode.DOCUMENT_VERSION));
        row.addCell(CellMode.genCell(CellMode.BELONG_TO_GROUP));
        row.addCell(CellMode.genCell(CellMode.APPLY_DATE));
        row.addCell(CellMode.genCell(CellMode.APPLY_USER));
        row.addCell(CellMode.genCell(CellMode.APPLY_CODE));
        row.addCell(CellMode.genCell(CellMode.APPLY_TYPE));
        row.addCell(CellMode.genCell(CellMode.APPLY_REASON));
        row.addCell(CellMode.genCell(CellMode.PHASE));
        row.addCell(CellMode.genCell(CellMode.COMMENT));
        //获取所有QA参与的流程
        DocumentFlowQuery documentFlowQuery = new DocumentFlowQuery(request.getPageIndex(), request.getPageSize());
        documentFlowQuery.setDocumentFlowId(request.getFlowId());
        List<GetDocumentFlowResponse> docs = documentFlowService.listLedgerData(documentFlowQuery).getRows();
        for (int i = 0; i < docs.size(); i++) {
            Row r = table.createRow();
            r.addCell(CellMode.genCell(String.valueOf(i + 1)));
            r.addCell(CellMode.genCell(docs.get(i).getDocumentPropertyName()));
            r.addCell(CellMode.genCell(docs.get(i).getDocumentName()));
            r.addCell(CellMode.genCell(docs.get(i).getDocumentCode()));
            r.addCell(CellMode.genCell(docs.get(i).getDocumentVersion()));
            r.addCell(CellMode.genCell(docs.get(i).getCreateUserGroupName()));
            r.addCell(CellMode.genCell(String.valueOf(docs.get(i).getCreateTime())));
            r.addCell(CellMode.genCell(docs.get(i).getCreateUserName()));
            r.addCell(CellMode.genCell("暂无"));
            r.addCell(CellMode.genCell(docs.get(i).getFlowTypeName()));
            r.addCell(CellMode.genCell(docs.get(i).getReason()));
            r.addCell(CellMode.genCell(docs.get(i).getPhaseName()));
            r.addCell(CellMode.genCell("无"));
        }
        MultiSheetExcelTemplate sheetExcelTemplate = new MultiSheetExcelTemplate();
        List<Table> tables = new ArrayList<>();
        tables.add(table);
        SXSSFWorkbook workbook = sheetExcelTemplate.create(tables, null);
        return workbook;
    }*/
}
